import logging
import unittest

import app
from utils import Utils
from api.staff_api import Staff_Api
from app import common_assert_login
from config import Logger

log = Logger(app.base_dir + '/log/all.log', level='info')


class Test_Staff(unittest.TestCase):
    staff_id = None

    def setUp(self):
        self.insert_staff = Staff_Api()
        self.token = app.Get_token().get_token()
        self.phone=Utils().phone_num()
        self.name=Utils.user_name()
    def test01_insert_staff(self):
        staff_data = {
            "username": self.name,
            "mobile": self.phone.strip("\n"),
            "timeOfEntry": "2021-11-24",
            "formOfEmployment": 2,
            "workNumber": "11111111",
            "departmentName": "打架部门",
            "departmentId": "1452251302175277056",
            "correctionTime": "2021-11-29T16:00:00.000Z"}
        re = self.insert_staff.staff_insert(staff_data, self.token)
        log.logger.info("响应数据={}".format(re.json()))
        common_assert_login(self, re, 200, 10000, True, "成功")
        Test_Staff.staff_id = re.json().get('data').get('id')

    def test02_upload_staff(self):
        json_data = {
            "username": "刘问问"
        }
        re = self.insert_staff.upload_staff(url_params=Test_Staff.staff_id, headers=self.token, json_data=json_data)
        log.logger.info("响应数据={}".format(re.json()))
        common_assert_login(self, re, 200, 10000, True, "成功")

    def test03_query_staff(self):
        re = self.insert_staff.query_staff(Test_Staff.staff_id, self.token)
        log.logger.info("响应数据={}".format(re.json()))
        common_assert_login(self, re, 200, 10000, True, "成功")

    def test04_delete_staff(self):
        re = self.insert_staff.delete_staff(Test_Staff.staff_id, self.token)
        log.logger.info("响应数据={}".format(re.json()))
        common_assert_login(self, re, 200, 10000, True, "成功")
